#include<iostream>
#include<string>
#include<vector>

#include "reader.h"

vector<string> read_line(string& line, const string& c)
{
  vector<string> result; 
  size_t pos;
  int offset = c.size();

  pos = line.find(c);  
  while (pos != string::npos) {
    result.push_back(line.substr(0, pos));
    line = line.substr(pos + offset);
    pos = line.find(c); 
  } 
  result.push_back(line);
  return result;
}

static string is("fpp");

  
Reader::Reader(istream& is, string& delimit)
  : is(is), delimiter(delimit) { }

Reader::Reader(istream& is)
  : is(is), delimiter("|") { }

vector<string> Reader::next()
{
  string s;
  getline(is, s);
  return read_line(s, delimiter);
}
